package com.bootdo.output.utils;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bootdo.common.domain.DictDO;
import com.bootdo.common.service.DictService;
import com.bootdo.output.domain.OutStorageDO;
import com.bootdo.output.domain.OutStorageDetailDO;
import com.bootdo.provider.domain.DriverDO;
import com.bootdo.provider.domain.GoodsInfoDO;
import com.bootdo.provider.domain.ProviderInfoDO;
import com.bootdo.provider.service.DriverService;
import com.bootdo.provider.service.GoodsInfoService;
import com.bootdo.provider.service.ProviderInfoService;
import com.bootdo.shop.domain.ShopDO;
import com.bootdo.shop.service.ShopService;
import com.bootdo.staff.domain.StaffUserDO;
import com.bootdo.staff.service.StaffUserService;

/**
 * 包装出库实体类
 * @author wlst
 *
 */
@Service
public class packageOutType {
	@Autowired
	private ProviderInfoService providerInfoService;
	
	@Autowired
	private GoodsInfoService goodsInfoService;
	 
	@Autowired
	private StaffUserService staffUserService;
	
	@Autowired
	private ShopService shopService;
	
	@Autowired
	private DriverService driverService;
	
	@Autowired
	private DictService dictService;
	
	/**
	 * 包装任务类
	 * @param do1
	 * @return
	 */
	public OutStorageDO packageOutStoragePojo(OutStorageDO do1) {
		//状态 加急 供应商 门店 司机 交接员
		Map<String, Object> map = new HashMap<>();
		map.put("value", do1.getOutstorageStatus());
		DictDO dict = dictService.list(map).get(0);
		do1.setOutstorageStatusName(dict.getName()) ;//状态
		map.put("value",do1.getOutstorageOrderid());
		dict = dictService.list(map).get(0);
		do1.setOutstorageOrderName(dict.getName());//加急
		DriverDO driver = driverService.get(do1.getOutstorageDriverId());//司机信息
		if(driver != null) {
			do1.setOutstorageDriverName(driver.getDriverName());
			do1.setOutstorageDriverPhone(driver.getDriverPhone());
		} 
		ProviderInfoDO  pro = providerInfoService.get(do1.getProviderId());//供货商
		do1.setProviderName(pro.getProviderFname());
		ShopDO shop=shopService.get(Long.valueOf(do1.getOutstorageShopid()));//门店
		do1.setShopName(shop.getShopName());
		if(do1.getOutstorageConnectId()!=null) {
			StaffUserDO userName = staffUserService.get(Long.valueOf(do1.getOutstorageConnectId()));
			do1.setOutstorageConnectName(userName.getStaffName());//用户名
			userName = null;
		}
		dict = null;
		pro = null;
		driver = null;
		shop = null;
		map.clear();
		System.gc();
		return do1;
	}
	public OutStorageDetailDO packageOutStorageDetailPojo(OutStorageDetailDO do1) {
		//商品 单位
		GoodsInfoDO	g=goodsInfoService.get(do1.getDatilGoodsid());
		do1.setgName(g.getGoodsName());//设置商品
		do1.setgCode(g.getGoodsCode());
		 g = null; 
		 System.gc();
		return do1;
	}
}
